#include<iostream>
#include<string>
#include<unistd.h>
#include<fcntl.h>

using namespace std;


int main()
{
    int fd1=open("./work/systemfile",O_WRONLY | O_CREAT,0640);
    string s1="Beginning Linux Programming";
    write(fd1,s1.c_str(),s1.size());
    
    if(lseek(fd1,-10,SEEK_END) == -1)
    {
        cout<<"lseek error"<<endl;
    }
    string s2="     ";
    write(fd1,s2.c_str(),s2.size());
    
    close(fd1);
    int fd2=open("./work/systemfile",O_WRONLY | O_CREAT);
    //偏移到末尾
    if(lseek(fd2,0,SEEK_END) == -1)
    {
        cout<<"lseek error"<<endl;
    }
    string s3="Third Edition";
    write(fd2,s3.c_str(),s3.size());

    close(fd2);
    return 0;
}
